Fix overrun
authorMichaël Meyer <hierophanie@gmail.com>
Thu, 4 Feb 2016 03:01:19 +0000 (04:01 +0100)
committerMichaël Meyer <hierophanie@gmail.com>
Thu, 4 Feb 2016 03:06:28 +0000 (04:06 +0100)
CMakeLists.txt
MANIFEST
Makefile
test/iterate.c
utf8proc.c

index ff0c819a3c302a2656fbefa94e1717395b5b7886..8958bcd2cbbea88b0ed12fac0257a7d24fb643a8 100644 (file)
@@ -9,7 +9,7 @@ project (utf8proc C)
 # Be sure to also update these in Makefile!
 set(SO_MAJOR 2)
 set(SO_MINOR 0)
-set(SO_PATCH 0)
+set(SO_PATCH 1)
 
 add_definitions (
   -DUTF8PROC_EXPORTS
index f79d541d9da4fd52e6af209fc15b8d6c8af950d1..0be40e0c80c39ad92be575958b9db92440124e9c 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -2,6 +2,6 @@ include/
 include/utf8proc.h
 lib/
 lib/libutf8proc.a
-lib/libutf8proc.so -> libutf8proc.so.2.0.0
-lib/libutf8proc.so.2 -> libutf8proc.so.2.0.0
-lib/libutf8proc.so.2.0.0
+lib/libutf8proc.so -> libutf8proc.so.2.0.1
+lib/libutf8proc.so.2 -> libutf8proc.so.2.0.1
+lib/libutf8proc.so.2.0.1
index ff5e77142b9c25b8afb3dc15f6bba5a0dea9fac8..117974809d32801ff1b3d3beb6740ec91a4511f3 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -21,7 +21,7 @@ UCFLAGS = $(CFLAGS) $(PICFLAG) $(C99FLAG) $(WCFLAGS) -DUTF8PROC_EXPORTS
 # Be sure to also update these in MANIFEST and CMakeLists.txt!
 MAJOR=2
 MINOR=0
-PATCH=0
+PATCH=1
 
 OS := $(shell uname)
 ifeq ($(OS),Darwin) # MacOS X
index 30b307dffc431fe5d7c1e9a59f1324c53eed011e..c1674b79952d66f8d678a68c647f6df9a891aca2 100644 (file)
@@ -13,11 +13,17 @@ static void testbytes(unsigned char *buf, int len, utf8proc_ssize_t retval, int
     utf8proc_int32_t out[16];
     utf8proc_ssize_t ret;
 
+    /* Make a copy to ensure that memory is left uninitialized after "len"
+     * bytes. This way, Valgrind can detect overreads.
+     */
+    unsigned char tmp[16];
+    memcpy(tmp, buf, len);
+
     tests++;
-    if ((ret = utf8proc_iterate(buf, len, out)) != retval) {
+    if ((ret = utf8proc_iterate(tmp, len, out)) != retval) {
         fprintf(stderr, "Failed (%d):", line);
         for (int i = 0; i < len ; i++) {
-            fprintf(stderr, " 0x%02x", buf[i]);
+            fprintf(stderr, " 0x%02x", tmp[i]);
         }
         fprintf(stderr, " -> %zd\n", ret);
         error++;
index ab23a8717669aab9ad864643f25b0d09d2e35e54..dc1000aed56affc7c06fe71060d053d673eb18bf 100644 (file)
@@ -128,7 +128,7 @@ UTF8PROC_DLLEXPORT utf8proc_ssize_t utf8proc_iterate(
   if ((uc - 0xc2) > (0xf4-0xc2)) return UTF8PROC_ERROR_INVALIDUTF8;
   if (uc < 0xe0) {         // 2-byte sequence
      // Must have valid continuation character
-     if (!utf_cont(*str)) return UTF8PROC_ERROR_INVALIDUTF8;
+     if (str >= end || !utf_cont(*str)) return UTF8PROC_ERROR_INVALIDUTF8;
      *dst = ((uc & 0x1f)<<6) | (*str & 0x3f);
      return 2;
   }